package com.smartsoft.service;

import android.net.Uri;
import com.smartsoft.R;
import com.smartsoft.model.CountryItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Performs data supplying for the application's components.
 */
public class DataManager {

    /**
     * List of avatar's drawable Ids.
     */
    private static final List<Integer> AVATAR_DRAW_IDS = new ArrayList<Integer>() {{
        add(R.drawable.neo_png);
        add(R.drawable.trin_png);
        add(R.drawable.mor_png);
    }};

    /**
     * Contains information about each country, which will be
     * displayed in carousel list.
     */
    private static final List<CountryItem> COUNTRIES_DATA = new ArrayList<CountryItem>() {{
        add(new CountryItem("Ukraine", R.drawable.ukraine_flag));
        add(new CountryItem("Canada", R.drawable.canada_flag));
        add(new CountryItem("United Kingdom", R.drawable.uk_flag));
        add(new CountryItem("Germany", R.drawable.germany_flag));
        add(new CountryItem("USA", R.drawable.usa_flag));
        add(new CountryItem("Argentina", R.drawable.argentina_flag));
        add(new CountryItem("Turkey", R.drawable.turcay_flag));
    }};

    /**
     * For lookuping resource's URI.
     */
    private static final String RESOURCE_PREFIX = "android.resource://";

    private static DataManager instance;

    private DataManager() {
    }

    public static DataManager getInstance() {
        if (instance == null) {
            synchronized (DataManager.class) {
                if (instance == null) {
                    instance = new DataManager();
                }
            }
        }
        return instance;
    }

    /**
     * Get resource URI determined by resIdentifier.
     *
     * @param resIdentifier resource identifier
     * @param packageName application's package name
     * @return URI of the resource
     */
    public static Uri getResourceUri(int resIdentifier, String packageName) {
        StringBuilder resourcePathBuilder = new StringBuilder();
        resourcePathBuilder.append(RESOURCE_PREFIX)
                .append(packageName)
                .append("/")
                .append(resIdentifier);
        return Uri.parse(resourcePathBuilder.toString());
    }

    public List<Integer> getAvatarDrawableIds() {
        return AVATAR_DRAW_IDS;
    }

    public List<CountryItem> getCountriesData() {
        return COUNTRIES_DATA;
    }

}
